<?php
namespace app\cms\lib;

use config\config;
use lib\db\DbTool;

class ArDBLib extends DbTool {

    public static function find($table)
    {
        $sonClass = get_called_class();
        if (method_exists($sonClass,'tableName')){
            $table = str_replace('@',config::get('db','prefix'),$sonClass::tableName());
            return parent::find($table);
        }
        @$table = end(explode('\\',$table));
        $table = substr($table,0,stripos($table,'Model'));
        preg_match_all('/[A-Z]+/', $table, $matches);
        foreach ($matches[0] as $k =>$v){
            if ($k == 0){
                continue;
            }
            $table = str_replace($v,'_'.$v,$table);
        }
        $table = strtolower($table);
        return parent::find(config::get('db','prefix').$table); // TODO: Change the autogenerated stub
    }

}